<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const { directLine, store } = testHelpers.createDirectLineEmulator();
        const telemetryEventTracking = [];

        WebChat.renderWebChat(
          {
            directLine,
            onTelemetry: event => {
              if (event?.name === 'send-status:change') {
                telemetryEventTracking.push(event.data);
              }
            },
            store
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        // WHEN: A message activity "sending to sent" is sent.
        await (await directLine.emulateOutgoingActivity('sending to sent')).resolveAll();
        await pageConditions.numActivitiesShown(1);

        // THEN: Two telemetry events should be emitted: "undefined -> sending" and "sending -> sent"
        expect(telemetryEventTracking).toEqual(
          expect.arrayContaining([
            {
              clientActivityID: expect.any(String),
              hasAttachment: 'false',
              key: expect.any(String),
              status: 'sending',
              type: 'message'
            },
            {
              clientActivityID: expect.any(String),
              hasAttachment: 'false',
              key: expect.any(String),
              prevStatus: 'sending',
              status: 'sent',
              type: 'message'
            }
          ])
        );
      });
    </script>
  </body>
</html>
